package com.crm.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.crm.pojo.common.ErrorMessage;
import com.crm.pojo.common.PageParams;
import com.crm.pojo.common.Result;
import com.crm.pojo.domain.Activity;
import com.crm.pojo.domain.Channel;
import com.crm.pojo.dto.ActivityDto;
import com.crm.pojo.dto.ActivityListDto;
import com.crm.pojo.vo.ActivityListVo;
import com.crm.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    /**
     * 活动列表查询
     *
     * @param dto
     * @return
     * @ModelAttribute ActivityListDto listDto,
     */
    @GetMapping("/clues/activity/list")
    public PageParams<ActivityListVo> list(ActivityListDto dto) {
        return activityService.list(dto);
    }

    /**
     * 活动来源查询
     *
     * @return
     */
//    @GetMapping("/system/dict/data/type/clues_item")
    public Result selCluesItem() {
        return Result.success();
    }

    /**
     * 渠道来源查询
     *
     * @return
     */
//    @GetMapping("/system/dict/data/type/channel_type")
    public Result selChannelType() {
        List<Channel> channelList = activityService.selChannel();
        return Result.success(channelList);
    }

    /**
     * 活动状态查询
     *
     * @return
     */
//    @GetMapping("/system/dict/data/type/activity_status")
    public Result selActivityStatus() {
        return Result.success();
    }

    /**
     * 莫名其妙的
     *
     * @param id
     * @return
     */
    @GetMapping("/system/notice/list/{id}")
    public Result selNotice(@PathVariable Integer id) {
        return Result.success();
    }

    /**
     * 新增活动
     *
     * @param dto
     * @return
     */
    @PostMapping("/clues/activity")
    public Result add(@RequestBody ActivityDto dto) {
        activityService.add(dto);
        return Result.success();
    }

    /**
     * 修改活动
     *
     * @param dto
     * @return
     */
    @PutMapping("/clues/activity")
    public Result update(@RequestBody ActivityDto dto) {
        activityService.update(dto);
        return Result.success();
    }

    /**
     * 回显活动数据
     *
     * @param id
     * @return
     */
    @GetMapping("/clues/activity/{id}")
    public Result selOne(@PathVariable Integer id) {
        return Result.success(activityService.selOne(id));
    }

    /**
     * 删除活动
     *
     * @param id
     * @return
     */
    @DeleteMapping("/clues/activity/{id}")
    public Result del(@PathVariable Integer id) {
        activityService.del(id);
        return Result.success();
    }

    /**
     * 添加合同页面获取渠道下拉列表
     *
     * @param channel
     * @return
     */
    /*  "path": "/clues/activity/listselect/1" */
    @GetMapping("/clues/activity/listselect/{channel}")
    public Result listSelect(@PathVariable String channel) {
        LambdaQueryWrapper<Activity> queryWrapper = Wrappers.<Activity>lambdaQuery().eq(Activity::getChannel, channel);
        List<Activity> list = activityService.list(queryWrapper);
        return Result.success(list);
    }
}
